package org.pupil.tolerant;

import org.pupil.common.constants.FaultTolerant;
import org.pupil.tolerant.impl.FailFastFaultTolerantStrategy;
import org.pupil.tolerant.impl.FailoverFaultTolerantStrategy;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 容错策略工厂
 * @Author: pupil
 * @Date: 2024/07/17 下午 4:26
 */
public class FaultTolerantFactory {

    private static Map<FaultTolerant,FaultTolerantStrategy> faultTolerantStrategyMap = new HashMap<>();

    static {
        faultTolerantStrategyMap.put(FaultTolerant.FailFast,new FailFastFaultTolerantStrategy());
        faultTolerantStrategyMap.put(FaultTolerant.Failover,new FailoverFaultTolerantStrategy());
    }

    public static FaultTolerantStrategy get(FaultTolerant faultTolerant){
        return faultTolerantStrategyMap.get(faultTolerant);
    }
}
